package com.he.heblog.dto;

import com.he.heblog.entity.Role;
import com.he.heblog.entity.User;
import com.he.heblog.entity.validInterface.addValid;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserDto extends User implements UserDetails {
//验证码
@NotBlank(groups = addValid.class)
@Size(min = 4,max = 4,groups = addValid.class)
public String Code;
//角色信息
private List<Role> roles;
private Integer isFollow;
    ////该用户的粉丝
//public List<User> fanList;
////该用户的关注用户
//public List<User> userList;
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> grantedAuthorities=new ArrayList<>();
        roles.forEach(
                role ->
                        grantedAuthorities.add( new SimpleGrantedAuthority(role.getRoleName())));
        return grantedAuthorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }



}
